package com.medium.house.service.impl;

import java.util.List;
import java.util.Map;

import com.medium.house.entity.HouseRegion;
import com.medium.house.response.HouseCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.medium.house.entity.HouseLayout;
import com.medium.house.repository.HouseLayoutMapper;
import com.medium.house.service.HouseLayoutService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;

@Service
public class HouseLayoutServiceImpl implements HouseLayoutService
{

    @Autowired
    private HouseLayoutMapper houseLayoutMapper;

    @Override
    public int add(HouseLayout dto)
    {
        return houseLayoutMapper.insert(dto);
    }

    @Override
    public int delete(long id)
    {
        return houseLayoutMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(HouseLayout dto)
    {
        return houseLayoutMapper.updateByPrimaryKey(dto);
    }

    @Override
    public HouseLayout get(long id)
    {
        return houseLayoutMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<HouseLayout> getByPage(
        int start,
        int limit,
        int orderby,
        int order)
    {
        if (start < 0) {start = 0;}
        if (limit <=0) {limit = 20;}
        if (orderby > HouseLayoutMapper.ORDERBY.length - 1 || orderby < 0) {orderby = 0;}
        if (order != 0) {order = 1;}

        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return houseLayoutMapper.selectByPage(start, limit, HouseLayoutMapper.ORDERBY[orderby], HouseLayoutMapper.ORDER[order], args);
    }

    @Override
    public List<Long> getIdsByPage(
        int start,
        int limit,
        int orderby,
        int order)
    {
        if (start < 0) {start = 0;}
        if (limit <=0) {limit = 20;}
        if (orderby > HouseLayoutMapper.ORDERBY.length - 1 || orderby < 0) {orderby = 0;}
        if (order != 0) {order = 1;}

        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return houseLayoutMapper.selectIdsByPage(start, limit, HouseLayoutMapper.ORDERBY[orderby], HouseLayoutMapper.ORDER[order], args);
    }

    @Override
    public long count()
    {
        Map<String, Object> args = new HashMap<>();
        // Add more parameters here
        return houseLayoutMapper.count(args);
    }
    @Override
    public List<HouseCondition> selectByCondition(int type, int status){
        Map<String, Object> args = new HashMap<String, Object>();
        if (type > 0){ args.put("type",type); }
        if (status > 0){ args.put("status",status); }
        return houseLayoutMapper.selectByCondition(args);
    }

}